package net.qiqb.core.domain.event.receiver;

import cn.hutool.core.util.ClassLoaderUtil;
import net.qiqb.core.domain.event.DomainEvent;

import java.util.List;

public class LocalDomainEventReceiver implements DomainEventReceiver {


    private DomainEventMulticaster domainEventMulticaster;

    public LocalDomainEventReceiver() {
    }

    public LocalDomainEventReceiver(DomainEventMulticaster domainEventMulticaster) {
        this.domainEventMulticaster = domainEventMulticaster;
    }

    public void setDomainEventMulticaster(DomainEventMulticaster domainEventMulticaster) {
        this.domainEventMulticaster = domainEventMulticaster;
    }

    @Override
    public List<ReceiveAckResp> receive(DomainEvent domainEvent) {

        // 扫描 应用中是否有监听器监听领域事件
        final int qty = domainEventMulticaster.findAndMulticastEvent(domainEvent);
        return List.of(new ReceiveAckResp(qty, "127.0.0.1"));
    }
}
